package mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Join {
	static String innerjoin =  "select * from A INNER JOIN B on A.id=B.id";//两个表交集
	static String naturejoin =  "SELECT * FROM A NATURAL JOIN B; ";//笛卡尔积
	//static String creatsql =  "";//笛卡尔积
	//static String creatsql =  "";
	//static String creatsql =  "";
	
	public static void main(String[] args)
	{
	     try {
	          Class.forName("com.mysql.cj.jdbc.Driver");     //加载MYSQL JDBC驱动程序   
	          //Class.forName("org.gjt.mm.mysql.Driver");
	         System.out.println("Success loading Mysql Driver!");
	        }
	        catch (Exception e) {
	          System.out.print("Error loading Mysql Driver!");
	          e.printStackTrace();
	        }
	     try {
	       Connection connect = DriverManager.getConnection(
	              "jdbc:mysql://172.16.63.135/test","root","000000");
	       PreparedStatement Statement=connect.prepareStatement(innerjoin);
	       ResultSet result=Statement.executeQuery(innerjoin);
	       while(result.next())
	       {
	    	   
	       System.out.println(result.getString(1));
	       }
	         //
	       
	       
	  } 
	     
	     catch(SQLException e)
		   {
	    	 e.printStackTrace();
	    	 System.out.println("查找失败！");
		   }
	 }
}
